/** Standard requestAnimFrame; see paulirish.com */
window.requestAnimFrame = (
    function(callback) {
      return window.requestAnimationFrame ||
          window.webkitRequestAnimationFrame ||
          window.mozRequestAnimationFrame ||
          window.oRequestAnimationFrame ||
          window.msRequestAnimationFrame ||
          function(callback) {
            window.setTimeout(callback, 1000 / 30);
          };
    })();

var renderer = new RenderManager();
renderer.registerRenderCallback(drawGrid);

function update() {
  window.requestAnimFrame(update);

  renderer.render();
}

function init() {
  // When API is ready...                                                         
  gapi.hangout.onApiReady.add(
    function(eventObj) {
      if (eventObj.isApiReady) {
        try {
          update();
        } catch (e) {
          console.log('init:ERROR');
          console.log(e);
        }
      }
    });
}

// Wait for gadget to load.                                                       
gadgets.util.registerOnLoadHandler(init);


















/*function init() {
  // When API is ready...                                                         
  gapi.hangout.onApiReady.add(
    function(eventObj) {
      if (eventObj.isApiReady) {
        try {
          initRenderManager();
          initGridRenderer();
        } catch (e) {
          console.log('init:ERROR');
          console.log(e);
        }
      }
    });
}

// Wait for gadget to load.                                                       
gadgets.util.registerOnLoadHandler(init);*/